package com.burry.action;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;

import net.sf.json.JSONObject;

import applelew.util.Debug;

import com.burry.bo.JSONResult;
import com.burry.services.ModelService;

public class ModelAction extends BaseAction {
	
	private InputStream inputStream;
	private String beginDate;
	private String endDate;
	private String modelType;
	private String disType;
	private String disValue;
	private String plusValue;
	
	private String catalog;
	private String catalogNum;
	private String goodId;
	
	
	public String getCatalog() {
		return catalog;
	}

	public void setCatalog(String catalog) {
		this.catalog = catalog;
	}

	public String getCatalogNum() {
		return catalogNum;
	}

	public void setCatalogNum(String catalogNum) {
		this.catalogNum = catalogNum;
	}

	public String getGoodId() {
		return goodId;
	}

	public void setGoodId(String goodId) {
		this.goodId = goodId;
	}

	public String getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(String beginDate) {
		this.beginDate = beginDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public String getModelType() {
		return modelType;
	}

	public void setModelType(String modelType) {
		this.modelType = modelType;
	}

	public String getDisType() {
		return disType;
	}

	public void setDisType(String disType) {
		this.disType = disType;
	}

	public String getDisValue() {
		return disValue;
	}

	public void setDisValue(String disValue) {
		this.disValue = disValue;
	}

	public String getPlusValue() {
		return plusValue;
	}

	public void setPlusValue(String plusValue) {
		this.plusValue = plusValue;
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public String listModelInit(){
		ModelService ms = new ModelService();
		List modelList = ms.getAllModel();
		JSONResult json = new JSONResult(modelList);
		JSONObject jsonRet = JSONObject.fromObject(json);  
		String allSize = jsonRet.toString();

		try {
			setInputStream(new ByteArrayInputStream(allSize.getBytes("utf-8")));
		} catch (UnsupportedEncodingException e) {
			Debug.logError(e.getMessage());
		}
		return SUCCESS;
	}
	
	public String saveGlobalModel(){
		//System.out.println("beginDate:" + beginDate);
		ModelService ms = new ModelService();
		ms.saveGlobalModel(beginDate, endDate, modelType, disType, disValue, plusValue);
		return SUCCESS;
	}
	
	public String saveCataModel(){
		ModelService ms = new ModelService();
		ms.saveCataModel(beginDate, endDate, modelType, disType, disValue, plusValue, catalog, catalogNum, goodId);
		return SUCCESS;
	}
}
